/**
 * BaseFragmentPagerAdapter.java
 * 
 * Purpose              :
 * 
 * Optional info        : 
 *
 * @author              : Van Hoang Phuong
 * 
 * @date                : Jun 5, 2012
 * 
 * @lastChangedRevision : 
 *
 * @lastChangedDate     :
 *
 */
package com.applink.sell_proof.fragment.adapter;

import lib.redmanit.pager.TitleProvider;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.util.Log;
import android.util.SparseArray;
import android.view.ViewGroup;

/**
 * @author Hoang Viet
 * 
 */
public abstract class BaseFragmentPagerAdapter extends
		FragmentStatePagerAdapter implements TitleProvider {
	private String[] TITLES;

	protected SparseArray<Fragment> mFragments = new SparseArray<Fragment>();

	public BaseFragmentPagerAdapter(FragmentManager fm, String[] titles) {
		super(fm);
		TITLES = titles;
	}

	@Override
	public abstract Fragment getItem(int index);

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		super.destroyItem(container, position, object);
		Log.i("BaseFragmentPagerAdapter", "getItem destroyItem_" + position);
		mFragments.remove(position);
	}

	@Override
	public int getCount() {
		return TITLES.length;
	}

	@Override
	public String getTitle(int position) {
		return TITLES[position];
	}

	public Fragment getFragmentAt(int position) {
		return mFragments.get(position);
	}
}
